package cqu.mvc.model;

import cqu.mvc.HibernateUtil;
import org.hibernate.Session;


/**
 * 用户DAO
 * 对应disk数据库中的userentity表
 * addUser方法用于注册
 * getUser方法用于登陆和查找用户
 */
public class UserDao {
	public static void addUser(String name, String pwd) {

		UserEntity userEntity = new UserEntity();
		userEntity.setName(name);
		userEntity.setPwd(pwd);

		HibernateUtil.commitEntity(userEntity);
	}
	public static UserEntity getUserByName(String name) {
		Session session = HibernateUtil.getSession();
		try {
			return session.get(UserEntity.class, name);
		} finally {
			session.close();
		}

	}

}
